﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Cryptography;

namespace Utility.Crypto
{
    public class SHA1
    {
        static public string ComputeSHA1ForFile(string pathToFile)
        {
            FileStream fs = new FileStream(pathToFile, FileMode.Open);

            SHA1CryptoServiceProvider cryptoTransformSHA1 = new SHA1CryptoServiceProvider();
            string hash = BitConverter.ToString(
                cryptoTransformSHA1.ComputeHash(fs)).Replace("-", "");

            fs.Close();

            return hash;
        }


        public static string ComputeSHA1(string text, Encoding enc)
        {
            
            byte[] buffer = enc.GetBytes(text);
            SHA1CryptoServiceProvider cryptoTransformSHA1 =
                                        new SHA1CryptoServiceProvider();
            
            return BitConverter.ToString(
                cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");
        }

        
    }

    public class MD5
    {
        public static string ComputeMD5Hash(string input)
        {
            // step 1, calculate MD5 hash from input
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
            byte[] hash = md5.ComputeHash(inputBytes);

            return BitConverter.ToString(hash);
        }
    }
    
}
